package com.woniuxy.listener;

import com.rabbitmq.client.AMQP;
import com.rabbitmq.client.Channel;
import com.woniuxy.entity.MyhOrder;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Component;

import java.io.IOException;

/**
 * @Author: 马宇航
 * @Todo: 死信消费者
 * @DateTime: 25/03/12/星期三 11:57
 * @Component: 成都蜗牛学苑
 **/
@Component
public class DeathListener {
    @RabbitListener(queues="deathQueue",ackMode="AUTO")
    public void deathQueueListener(MyhOrder order, Channel channel, Message message) throws IOException {
        System.out.println("死信的消费："+order);
    }
    //正常处理，目前队列中有5条数据还没有处理
    @RabbitListener(queues="normal5Queue")
    public void normal5QueueListener(MyhOrder order, Channel channel, Message message) throws IOException {
        System.out.println("正常不消费："+order);
        System.out.println(message.getMessageProperties().getDeliveryTag());
        //正常消费
        channel.basicAck(message.getMessageProperties().getDeliveryTag(), false);
        //拒绝消费，通常在catch里面处理 requeue=false，不重入队列
        channel.basicNack(message.getMessageProperties().getDeliveryTag(), false, false);
    }
}
